home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / graphic / boxright.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  6.4 KB  |  240 lines

  1. ;void box_right(box,col,row,width,depth);
  2. ;  unsigned char  *box,*col,*row,width,depth;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _video_buffer:word
  6.     EXTRN  _snow_protect:byte
  7.  
  8. box_seg EQU  [bp-2]
  9. box_ofs EQU  [bp-4]
  10. col_seg EQU  [bp-6]
  11. col_ofs EQU  [bp-8]
  12. row_seg EQU  [bp-10]
  13. row_ofs EQU  [bp-12]        
  14. width    EQU  [bp-14]        
  15. depth   EQU  [bp-16]        
  16. snow    EQU  [bp-18]        
  17. endofbox EQU  [bp-20]    
  18. toppos  EQU  [bp-22]        
  19. rghtpos EQU  [bp-24]        
  20.  
  21. _TEXT    SEGMENT  BYTE PUBLIC 'CODE'
  22.     ASSUME CS:_TEXT
  23.     PUBLIC _box_right
  24. _box_right proc near
  25.     push bp            ;
  26.     mov  bp,sp        ;set stack frame
  27.     sub  sp,24        ;make room to hold parameters
  28.     push di            ;
  29.     push si            ;
  30.     cmp  _memory_model,0    ;near or far?
  31.     jle  begin        ;jump if near
  32.     inc  bp            ;else add 2 to BP
  33.     inc  bp            ;
  34. begin:    push ds            ;save Turbo's DS
  35.     mov  dx,_video_buffer    ;grab _video_buffer
  36.     mov  bl,_snow_protect    ;
  37.     mov  snow,bl        ;save it
  38.     cmp  _memory_model,2    ;data near or far?
  39.     jb   L0            ;jump if near
  40.     push [bp+6]        ;move parameters to SP offsets
  41.     push [bp+10]
  42.     push [bp+14]
  43.     push [bp+4]
  44.     push [bp+8]
  45.     push [bp+12]
  46.     push [bp+16]
  47.     push [bp+18]
  48.     jmp  short L00
  49. L0:    push ds            ;near case
  50.     push ds
  51.     push ds
  52.     push [bp+4]
  53.     push [bp+6]
  54.     push [bp+8]
  55.     mov  al,[bp+10]
  56.     sub  ah,ah
  57.     push ax
  58.     mov  al,[bp+12]
  59.     push ax
  60. L00:    cmp  _memory_model,0    ;check code model again
  61.     jle  L000        ;jump if near
  62.     dec  bp            ;unadjust BP so all BP offsets same
  63.     dec  bp            ;
  64. L000:    pop  depth        ;set intermediate values
  65.     pop  width
  66.     pop  row_ofs
  67.     pop  col_ofs
  68.     pop  box_ofs
  69.     pop  row_seg
  70.     pop  col_seg
  71.     pop  box_seg
  72.     mov  ax,col_seg        ;ES:DI pts to Col
  73.     mov  es,ax        ;
  74.     mov  di,col_ofs        ;
  75.     sub  cx,cx        ;
  76.     mov  cl,es:[di]        ;get column position
  77.     jcxz I1            ;quit if column is zero
  78.     dec  cx            ;count from zero
  79.     mov  ax,cx        ;copy to AX
  80.     add  ax,width        ;add width
  81.     cmp  ax,78        ;in range?
  82.     jna  J1            ;jump ahead if so
  83. I1:    jmp  T1            ;else quit routine
  84. J1:    add  cx,3        ;add 2 (+ inc) to col pos
  85.     mov  es:[di],cl        ;change the setting
  86.     sub  cx,3        ;back to old col position
  87.     mov  ax,box_seg        ;segment of Box
  88.     mov  es,ax        ;load in ES
  89.     mov  di,box_ofs        ;offset of Box
  90.     mov  ax,depth        ;depth to AX
  91.     dec  ax            ;dec for test
  92.     cmp  ax,24        ;in range?
  93.     jna  K1            ;jump ahead if so
  94.     jmp  T1            ;else quit routine
  95. K1:    inc  ax            ;readjust
  96.     mov  bx,width        ;width to BX
  97.     dec  bx            ;dec for test
  98.     cmp  bx,79        ;in range?
  99.     jna  L1            ;jump ahead if so
  100.     jmp  T1            ;else quit
  101. L1:    inc  bx            ;readjust
  102.     mul  bl            ;width times depth
  103.     shl  ax,1        ;double for attributes
  104.     add  ax,di        ;offset to end of Box
  105.     mov  endofbox,ax    ;save end of box ptr
  106.     mov  di,ax        ;pt ES:DI to end of Box
  107.     mov  ax,row_seg        ;DS:SI pts to Row
  108.     mov  ds,ax        ;
  109.     mov  si,row_ofs        ;
  110.     sub  ax,ax        ;
  111.     mov  al,[si]        ;get row value
  112.     dec  ax            ;count from zero
  113.     cmp  ax,24        ;in range?
  114.     jna  M1            ;jump ahead if so
  115.     jmp  T1            ;else quit
  116. M1:    mov  bl,160        ;bytes per row
  117.     mul  bl            ;calculate row offset
  118.     shl  cx,1        ;col offset
  119.     add  ax,cx        ;add to row offset
  120.     mov  si,ax        ;SI pts to topleft corner
  121.       mov  toppos,si        ;save it
  122.     mov  ax,dx        ;_video_buffer
  123.     mov  ds,ax        ;move to DS
  124.     mov  ax,width        ;get width
  125.     shl  ax,1        ;double for attributes
  126.     add  si,ax        ;DS:SI pts to topright
  127.     mov  rghtpos,si        ;copy position
  128.     cld            ;set direction
  129.     mov  cx,depth        ;get depth
  130.     mov  dx,si        ;DX holds start col
  131. N1:    mov  si,dx        ;set start col
  132.     call Writeit        ;write a char
  133.     call Writeit        ;write another
  134.     add  dx,160        ;forward one row
  135.     loop N1            ;do next row
  136.     mov  ax,ds        ;DS to AX
  137.     mov  es,ax        ;now ES pts to screen too
  138.     mov  si,rghtpos        ;top right position + 2
  139.     sub  si,2        ;minus 2
  140.     mov  di,si        ;copy to DI
  141.     add  di,4        ;will shift right by 2
  142.     std            ;reverse direction flag
  143.     cmp  ax,0b800h        ;graphics card?
  144.     jb   O1            ;jump if monochrome
  145.     inc  di            ;forward ptr to start
  146.     inc  si            ;other ptr
  147. O1:    mov  dx,depth        ;depth
  148.     mov  ax,width        ;width
  149. P1:    mov  cx,ax        ;width to CX
  150.     push di            ;save target start
  151.     push si            ;save source start
  152. Q1:    call Writeit        ;write a char
  153.     loop Q1            ;go do next
  154.     pop  si            ;restore source start
  155.     pop  di            ;restore target start
  156.     add  di,160        ;forward dest ptr
  157.     add  si,160        ;forward source ptr
  158.     dec  dx            ;dec row counter
  159.     jnz  P1            ;loop till image shifted
  160.     cld            ;reset direction flag
  161.     mov  ax,box_seg        ;segment of Box
  162.     mov  ds,ax        ;move to DS
  163.     mov  si,box_ofs        ;offset of Box
  164.     mov  di,toppos        ;ES:DI pts to old topleft
  165.     mov  cx,depth        ;get depth
  166.     mov  dx,width        ;get width
  167.     sub  dx,2        ;minus 2 for 2 columns
  168.     shl  dx,1        ;double for attributes
  169. R1:    call Writeit        ;write a char
  170.     call Writeit        ;write another
  171.     add  di,156        ;forward target ptr
  172.     add  si,dx        ;forward source ptr
  173.     loop R1            ;do next row
  174.     mov  ax,box_seg        ;segment of Box
  175.     mov  es,ax        ;move to ES
  176.     mov  di,box_ofs        ;offset of Box
  177.     mov  ax,col_seg        ;segment of Col
  178.     mov  ds,ax        ;move to DS
  179.     mov  si,endofbox    ;offset of Col
  180.     add  di,4        ;DI to new start of Box
  181.     mov  cx,depth        ;get depth
  182. S1:    add  di,dx        ;forward target ptr
  183.     movsw            ;move one char of two
  184.     movsw            ;move the next
  185.     loop S1            ;go move 2 more chars
  186.     mov  di,box_ofs        ;offset to start of Box
  187.     mov  si,di        ;copy to SI
  188.     add  si,4        ;SI 2 chars to the right
  189.     mov  ax,depth        ;depth
  190.     mov  cx,width        ;width
  191.     mul  cl            ;size of Box
  192.     mov  cx,ax        ;move to CX as counter
  193.     rep  movsw        ;shift all downwards
  194.     jmp  short U1        ;jump to end
  195. T1:    pop  bx            ;balance stack if error
  196. U1:    sti            ;reenable interrupts
  197.     pop  ds            ;
  198.     pop  si            ;
  199.     pop  di            ;
  200.     add  sp,24        ;restore stack pointer
  201.     pop  bp            ;
  202.     cmp  _memory_model,0    ;quit
  203.     jle  quit        ;
  204.     db   0CBh        ;RET far
  205. quit:    ret            ;RET near
  206. _box_right endp
  207. Writeit    PROC
  208.     push dx            ;save DX
  209.     push ax            ;save AX
  210.     mov  dx,es        ;get target segment
  211.     mov  ax,ds        ;get source segment
  212.     cmp  ax,dx        ;is source larger?
  213.     jna  A1            ;jump if not
  214.     mov  dx,ax        ;else use source
  215. A1:    cmp  byte ptr snow,0    ;protect against snow?
  216.     je   F1            ;jump ahead if not
  217.     mov  dx,3dah        ;status byte address
  218. B1:    in   al,dx        ;get status byte
  219.     test al,1        ;test bit
  220.     jnz  B1            ;loop till 0
  221. C1:    in   al,dx        ;get status byte
  222.     test al,1        ;test bit
  223.     jz   C1            ;loop till 1
  224.     movsb            ;move a character
  225. D1:    in   al,dx        ;get status byte
  226.     test al,1        ;test bit
  227.     jnz  D1            ;loop till 0
  228. E1:    in   al,dx        ;get status byte
  229.     test al,1        ;test bit
  230.     jz   E1            ;loop till 1        
  231.     movsb            ;move a character
  232.     jmp  short G1        ;jump ahead and quit
  233. F1:    movsw            ;move the character
  234. G1:    pop  ax            ;restore AX
  235.     pop  dx            ;restore DX
  236.     ret            ;
  237. Writeit    endp
  238. _TEXT    ENDS
  239.     END
  240.